$(function (){
    if(error){
    layer.alert(error);
    }
    fetchKind();
    if(kind_id.trim() !== ""){
        $("#comboList").children("[name="+kind_id+"]").prop("selected",true);
    }
    $("#sub-btn").click(function (){
        let foodId =$(":input[name = food_id]").val();
        if(foodId.trim() === ""){
            layer.msg("顾客编号不可为空");
            return false;
        }
        let kindId =$(":input[name = kind_id]").val();
        if(kindId.trim() === ""){
            layer.msg("顾客编号不可为空");
            return false;
        }
        let name = $(":input[name= name]").val();
        if(name.trim() === ""){
            layer.msg("姓名不可为空");
            return  false;
        }
        let price = $(":input[name= price]").val();
        if(price.trim() === ""){
            layer.msg("价格不可为空");
            return  false;
        }
        let text = $(":input[name = kind_id]").val();
        let $option =   $("#comboList").children("[name="+text+"]")
        if($option.length == 0){
            layer.msg("该分类编号不存在");
            return;
        }
        console.log("前端校验不错")
        $("#emp-form").submit();
    });

    $("#comboList").change(function (){
        $(":input[name = kind_id]").val($(this).val());
    });
    $(":input[name = kind_id]").blur(function (){
        let text = $(":input[name = kind_id]").val();
        let $option =   $("#comboList").children("[name="+text+"]")
        if($option.length == 0){
            layer.msg("该分类编号不存在");
            return;
        }
       $option.prop("selected",true);
    });
});
function fetchKind(){
    // layer.msg("触发");

        let url = ctx + "/kind/comboList";
        $.post(url,{},function(resp){
            let klist = resp.klist;
            $("#comboList").empty();
            klist.forEach(function (item){
               $("#comboList").append($("<option value='"+item.kindId+"' name='"+item.kindId+"'>"+item.name+"</option>"));
            });
        });

}